package ai.people.netmon.twitter.view.controller;

import ai.people.netmon.framework.domain.twitter.view.entity.TwitterAccountView;
import ai.people.netmon.framework.domain.twitter.view.request.QueryViewRequest;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import ai.people.netmon.twitter.view.service.TwitterAccountViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 视图接口
 *
 * @author zhenglin
 * @since 2022/3/18
 */
@RestController
@RequestMapping("/view")
public class TwitterAccountViewController {
    @Autowired
    TwitterAccountViewService service;

    /**
     * 分页查询
     *
     * @param request 请求
     * @return {@link Result}<{@link PageResponse}<{@link TwitterAccountView}>>
     */
    @PostMapping("/list")
    public Result<PageResponse<TwitterAccountView>> list(@RequestBody QueryViewRequest request){
        PageResponse<TwitterAccountView> response = service.listViews(request);
        return ResultUtil.success(response);
    }

    /**
     * 获取用户信息
     *
     * @param accountName 帐户名称
     * @return {@link Result}<{@link TwitterAccountView}>
     */
    @GetMapping("/{accountName}")
    public Result<TwitterAccountView> getUsersView(@PathVariable("accountName") String accountName){
        TwitterAccountView one = service.getView(accountName);
        return ResultUtil.success(one);
    }
}
